﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ObviousCode.Aspect.PluginLibrary.Interfaces;
using ObviousCode.Common.Utils.Library.Dictionaries;
using ZooKeeperSample.Interfaces;

namespace ZooKeeperSample.Factories
{
    public class Factory<T> where T : IAspectItem, IPropertiesHost, new()
    {
        public T CreateInstance(params object[] args)
        {
            if (args.Length > 0 && args[0] is PropertyDictionary)
            {
                return LoadInstance(args[0] as PropertyDictionary);
            }
            else
            {
                return new T();
            }
        }

        private T LoadInstance(PropertyDictionary properties)
        {
            T t = CreateInstance();

            t.Properties = properties;

            return t;
        }   

        public Type InstanceType
        {
            get { return typeof(T); }
        }

        public object SaveInstance(T item)
        {
            return item.Properties;
        }

    }
}
